package org.bigk.invoices.actions;

import java.util.List;

import org.bigk.invoices.exceptions.ServiceException;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;


public abstract class AbstractCRUDAction<E> extends InvoicesActionSupport
		implements ModelDriven<E>, Preparable {
	
	private static final long serialVersionUID = -3615777339109730533L;

	public static final String LIST = "list";
	public static final String REDIRECT_LIST = "redirectList";
	public static final String SHOW = "show";

	protected E model;

	protected List<E> list;

	@Override
	public void prepare() throws Exception {}
	
	public void prepareCreate() throws ServiceException {}
	
	public String create() throws ServiceException {
		return INPUT;
	}

	public void prepareList() throws ServiceException {}

	public String list() throws ServiceException {
		return LIST;
	}

	public void prepareShow() throws ServiceException {}

	public String show() throws ServiceException {
		if (model == null) {
			addActionError(getText("error.not_found"));
			return REDIRECT_LIST;
		}
		return SUCCESS;
	}

	public void prepareEdit() throws ServiceException {}

	public String edit() throws ServiceException {
		return INPUT;
	}

	public void prepareDelete() throws ServiceException {};

	public String delete() throws ServiceException {
		return SHOW;
	};

	public void prepareSave() throws ServiceException {};

	public String save() throws ServiceException {
		return SHOW;
	};

	public void prepareUpdate() throws ServiceException {};

	public String update() throws ServiceException {
		return SHOW;
	};

	public E getModel() {
		return model;
	}

	public void setModel(E model) {
		this.model = model;
	}

	public List<E> getList() {
		return list;
	}

	public void setList(List<E> list) {
		this.list = list;
	}

	
}
